package com.hos.db.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.hos.db.create.art.ArticleContentEntity;
import com.hos.utile.JsonUtile;

import java.util.Date;
import java.util.List;

/**
 * 文章
 * Created by guom on 2018/10/27.
 */
public class ArtEntity {
    //文章id
    public String artId;
    // 文章标题
    public String artTitle;
    // 文章封面
    public String artImgCover;
    // 文章内容
    @JsonIgnore
    public String artContent;
    public List<ArticleContentEntity> artContents;
    // 文章所有者
    public String artOwner;
    // 文章所有者id
    public String artOwnerId;
    // 文章作者
    public String artAuthor;
    // 文章创建时间
    public Date artCreateTime;
    // 文章修改时间
    public Date artUpdateTime;
    // 文章阅读数量
    public int artRead;
    //文章点赞数量
    public int artLike;
    //状态 1：审核状态 2：审核通过状态
    public Integer artState;
    //状态 1:上架 2：下架
    public Integer artIssue;

    //


    public String getArtImgCover() {
        return artImgCover;
    }

    public void setArtImgCover(String artImgCover) {
        this.artImgCover = artImgCover;
    }

    public String getArtId() {
        return artId;
    }

    public void setArtId(String artId) {
        this.artId = artId;
    }

    public String getArtTitle() {
        return artTitle;
    }

    public void setArtTitle(String artTitle) {
        this.artTitle = artTitle;
    }

    public String getArtContent() {
        return artContent;
    }

    public void setArtContent(String artContent) {
        if (artContent != null && !artContent.equals("")) {
            artContents = (List<ArticleContentEntity>) JsonUtile.json2Obj(artContent,
                    List.class, ArticleContentEntity.class);
            onMsgJson();
            return;
        }
        this.artContent = artContent;
    }

    @JsonIgnore
    private void onMsgJson() {
        if (artContents == null) {
            return;
        }
        if (artContents.size() == 0) {
            return;
        }
        for (int i = 0; i < artContents.size(); i++) {
            ArticleContentEntity art = artContents.get(i);
            String artMsg = art.artMsg;
            artMsg = artMsg.replaceAll("&quot;", "\"");
            art.artMsg = artMsg;
        }
    }

    public String getArtOwner() {
        return artOwner;
    }

    public void setArtOwner(String artOwner) {
        this.artOwner = artOwner;
    }

    public String getArtOwnerId() {
        return artOwnerId;
    }

    public void setArtOwnerId(String artOwnerId) {
        this.artOwnerId = artOwnerId;
    }

    public String getArtAuthor() {
        return artAuthor;
    }

    public void setArtAuthor(String artAuthor) {
        this.artAuthor = artAuthor;
    }

    public Date getArtCreateTime() {
        return artCreateTime;
    }

    public void setArtCreateTime(Date artCreateTime) {
        this.artCreateTime = artCreateTime;
    }

    public Date getArtUpdateTime() {
        return artUpdateTime;
    }

    public void setArtUpdateTime(Date artUpdateTime) {
        this.artUpdateTime = artUpdateTime;
    }

    public int getArtRead() {
        return artRead;
    }

    public void setArtRead(Integer artRead) {
        if (artRead == null) {
            artRead = 0;
        }
        this.artRead = artRead;
    }

    public int getArtLike() {
        return artLike;
    }

    public void setArtLike(Integer artLike) {
        if (artLike == null) {
            artLike = 0;
        }
        this.artLike = artLike;
    }


    public Integer getArtState() {
        return artState;
    }

    public void setArtState(Integer artState) {
        if (artState == null) {
            artState = 2;
        }
        this.artState = artState;
    }

    public void setArtIssue(Integer artIssue) {
        if (artIssue == null) {
            artIssue = 2;
        }
        this.artIssue = artIssue;
    }

    public Integer getArtIssue() {
        return artIssue;
    }


    public List<ArticleContentEntity> getArtContents() {
        return artContents;
    }

    public void setArtContents(List<ArticleContentEntity> artContents) {
        this.artContents = artContents;
    }
}
